package com.qifenqian.turbot.module.model

import android.content.Context

import com.qifenqian.turbot.base.BaseModel
import com.qifenqian.turbot.module.contract.MarketingContract
import com.qifenqian.turbot.module.entity.response.marketing.*
import com.qifenqian.turbot.net.ModelCallback
import com.qifenqian.turbot.net.NetObserver

/**
 * @author H
 * @createTime 2019/1/18 10:03
 * @description
 * @see
 * @since
 */
class MarketingModel(context: Context) : BaseModel(context), MarketingContract.Model {

    override fun saveEarlyPayDiscount(request: EarlyPayDiscountEntity, callback: ModelCallback<Nothing>) {
        mClient!!.saveEarlyPayDiscount(request)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getEarlyPayDiscount(callback: ModelCallback<EarlyPayDiscountEntity>) {
        mClient!!.getEarlyPayDiscount()
                .subscribe(object : NetObserver<EarlyPayDiscountEntity>(mContext, true) {
                    override fun onSuccess(msg: String?, t: EarlyPayDiscountEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun saveFullReduction(request: FullReductionEntity, callback: ModelCallback<Nothing>) {
        mClient!!.saveFullReduction(request)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getFullReduction(callback: ModelCallback<FullReductionEntity>) {
        mClient!!.getFullReduction()
                .subscribe(object : NetObserver<FullReductionEntity>(mContext, true) {
                    override fun onSuccess(msg: String?, t: FullReductionEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun saveShareDiscount(request: ShareDiscountEntity, callback: ModelCallback<Nothing>) {
        mClient!!.saveShareDiscount(request)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun saveFreeTimeDiscountDetail(request: FreeTimeDiscountDetailEntity, callback: ModelCallback<Nothing>) {
        mClient!!.saveFreeTimeDiscountDetail(request)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getFreeTimeDiscountDetail(callback: ModelCallback<FreeTimeDiscountDetailEntity>) {
        mClient!!.getFreeTimeDiscountDetail()
                .subscribe(object : NetObserver<FreeTimeDiscountDetailEntity>(mContext, true) {
                    override fun onSuccess(msg: String?, t: FreeTimeDiscountDetailEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getFreeTimeDiscount(callback: ModelCallback<FreeTimeDiscountDetailEntity>) {
        mClient!!.getFreeTimeDiscount()
                .subscribe(object : NetObserver<FreeTimeDiscountDetailEntity>(mContext, true) {
                    override fun onSuccess(msg: String?, t: FreeTimeDiscountDetailEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun deleteFreeTimeDiscount(id: Int, callback: ModelCallback<Nothing>) {
        mClient!!.deleteFreeTimeDiscount(id)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getShareDiscount(callback: ModelCallback<ShareDiscountEntity>) {
        mClient!!.getShareDiscount()
                .subscribe(object : NetObserver<ShareDiscountEntity>(mContext, true) {
                    override fun onSuccess(msg: String?, t: ShareDiscountEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getDiscountDishes(callback: ModelCallback<DiscountDishEntity>) {
        mClient!!.getDiscountDishes()
                .subscribe(object : NetObserver<DiscountDishEntity>(mContext, true) {
                    override fun onSuccess(msg: String?, t: DiscountDishEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun saveSpecialDishes(request: SpecialDishEntity, callback: ModelCallback<Nothing>) {
        mClient!!.saveSpecialDishes(request)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun deleteSpecialDish(id: Int, callback: ModelCallback<Nothing>) {
        mClient!!.deleteSpecialDish(id)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getSpecialDishes(callback: ModelCallback<SpecialDishEntity>) {
        mClient!!.getSpecialDishes()
                .subscribe(object : NetObserver<SpecialDishEntity>(mContext, true) {
                    override fun onSuccess(msg: String?, t: SpecialDishEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getMarketingPage(callback: ModelCallback<MarketingHomeEntity>) {
        mClient!!.getMarketingPage()
                .subscribe(object : NetObserver<MarketingHomeEntity>(mContext, false) {
                    override fun onSuccess(msg: String?, t: MarketingHomeEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }
}
